package models;

import java.util.List;
import java.util.Map;

import models.mappers.DepartmentMapper;
import models.mappers.UserMapper;

import org.apache.ibatis.session.SqlSession;

import vos.DepartSearchVo;

import com.aton.db.SessionFactory;

public class Department implements java.io.Serializable {
	public final static String TABLE_NAME="gy_department";
	public String departmentid;
	public String departmentcode;
	public String departmentname;
	public Boolean isflag;
	public Integer sort;
	
	public Department(){
		
	}
	public Department(String departmentid, String departmentcode,
			String departmentname, Boolean isflag, Integer sort) {
		super();
		this.departmentid = departmentid;
		this.departmentcode = departmentcode;
		this.departmentname = departmentname;
		this.isflag = isflag;
		this.sort = sort;
	}
	
	public String getDepartmentid() {
		return departmentid;
	}
	public void setDepartmentid(String departmentid) {
		this.departmentid = departmentid;
	}
	public String getDepartmentcode() {
		return departmentcode;
	}
	public void setDepartmentcode(String departmentcode) {
		this.departmentcode = departmentcode;
	}
	public String getDepartmentname() {
		return departmentname;
	}
	public void setDepartmentname(String departmentname) {
		this.departmentname = departmentname;
	}
	public Boolean getIsflag() {
		return isflag;
	}
	public void setIsflag(Boolean isflag) {
		this.isflag = isflag;
	}
	public Integer getSort() {
		return sort;
	}
	public void setSort(Integer sort) {
		this.sort = sort;
	}
	/**
	 * 统计返回页面的总条数
	 *
	 * @Title: countDepartment 
	 * @param departmentCode 部门编号
	 * @param departmentName 部门名称
	 * @return
	 * @return: long
	 */
	public static long countDepartment(DepartSearchVo vo){
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            return mapper.countDepartment(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 获取部门记录
	 *
	 * @Title: listDepartment 
	 * @param page 页码
	 * @param pagesize 页大小
	 * @param departmentCode 部门编码
	 * @param departmentName 部门名称
	 * @return
	 * @return: List<Department> 部门列表
	 */
	public static List<Department> listDepartment(DepartSearchVo vo) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            return mapper.listDepartment(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 启用部门
	 *
	 * @Title: enableDepartment 
	 * @param id 部门id组
	 * @return: void
	 */
	public static void enableDepartment(Map<String,List<String>> map) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            mapper.enableDepartment(map);
            ss.commit();
        } finally {
            ss.close();
        }
	}
	/**
	 * 停用部门
	 *
	 * @Title: disableDepartment 
	 * @param map id部门id组
	 * @return: void
	 */
	public static void disableDepartment(Map<String, List<String>> map) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            mapper.disableDepartment(map);
            ss.commit();
        } finally {
            ss.close();
        }
	}
	/**
	 * 删除部门
	 *
	 * @Title: disableDepartment 
	 * @param map id部门id组
	 * @return: void
	 */
	public static void betchDeleteDepartment(Map<String, List<String>> map) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            mapper.betchDeleteDepartment(map);
            ss.commit();
        } finally {
            ss.close();
        }
	}
	/**
	 * 根据id查询数据
	 *
	 * @Title: findById 
	 * @param id 部门id
	 * @return
	 * @return: Department
	 */
	public static Department findById(String id) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            return mapper.findByIdDepartment(id);
        } finally {
            ss.close();
        }
	}
	/**
	 * 根据id删除数据
	 *
	 * @Title: deleteDepartment 
	 * @param id 部门id
	 * @return: void
	 */
	public static void deleteDepartment(String id) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            mapper.deleteByIdDepartment(id);
            ss.commit();
        } finally {
            ss.close();
        }
	}
	/**
	 * 检验部门编号是否存在
	 *
	 * @Title: checkCode 
	 * @param departmentCode 部门编号
	 * @return: void
	 */
	public static Department checkCode(String departmentCode) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DepartmentMapper mapper = ss.getMapper(DepartmentMapper.class);
            return mapper.findByCodeDepartment(departmentCode);
        } finally {
            ss.close();
        }
	}
}
